var $HOST = "";
var api = {
	// 病人信息列表
	patients:{
		url: $HOST + "/patients",
		cache:false,
		success:function(res){},
		error:function(){},
		complete:function(){
			// 调试数据
			// vm.patients = patents;
		}
	},
	// 病人信息
	patientInfo:{
		url: $HOST + "/patients/:lisId",
		cache:false,
		success:function(res){},
		error:function(){},
		complete:function(){
			// 调试数据
			// vm.patientInfo = patentDetail;
		}
	},
	// 病人用药列表
	patientsInfoResult:{
		url: $HOST + "/patients/:lisId/results",
		cache:false,
		success:function(res){},
		error:function(){},
		complete:function(){
			// 调试数据
			// vm.patientsInfoResult = patientsResults;
		}
	}
}

var vm = new Vue({
	el:"#body",
	data:{
		patients:[],
		patientsActive:"",
		patientInfo:{
			"lisId": "2012010500001A",
            "testNo": "103", //测试号
            "name": "21",
            "mzh": "", //门诊号
            "zyh": "", //住院号
            "tjh": "", //体检号
            "sex": "0",
            "age": "11",
            "diagnosis": "", //诊断
            "doctor": "", //申请医生
            "department": "感染二科", //申请部门
            "bedNo": "", //床号
            "rectime": "37分 17秒",//接收时间
            "sampleType": "血浆", //标本类型
            "sampleStatus": "", //标本状态
            "comboName": "电解质八项",
            "operator": "Admin", //操作者
            "reportor": "Admin", //报告者
            "checker": "Admin",  //审核者
            "barNo": "", //条码
            "machineType": "OMNIS",//设备类型
            "registerDate": "0" //登记日期
		},
		patientsInfoResult:[]

	},
	created: function () {
		this.getByPatientsList();
	},
	methods:{
		// 获取某一个病人的值
		getPatientById: function(lisId){
			vm.patientsActive = lisId;
			vm.getPatentInfo(lisId);
			vm.getPatientMedicals(lisId);
		},
		// 获取病人列表数据
		getByPatientsList:function(){
			var getPatientsList  = api.patients;
			getPatientsList.success = function(res){
				// 调试数据
				
				vm.patients = res;
				vm.patientsActive = res[0].lisId;
			}
			$.ajax(getPatientsList);
		},
		// 获取病人详情
		getPatentInfo:function(lisId){
			var patentInfo  = api.patientInfo;
			patentInfo.url = patentInfo.url.replace(":lisId", lisId);
			patentInfo.success = function(res){
				// 调试数据
				for(var key in vm.patientInfo){
					if(res[key]===null || res[key] === undefined){
						res[key] = "";
					}
					vm.patientInfo[key] = res[key];
				}
			}
			$.ajax(patentInfo);
		},
		getPatientMedicals:function(lisId){
			var patientsInfoResult  = api.patientsInfoResult;
			patientsInfoResult.url = patentInfo.url.replace(":lisId", lisId);
			patientsInfoResult.success = function(res){
				// 调试数据
				for(var key in vm.patientInfo){
					if(res[key]===null || res[key] === undefined){
						res[key] = "";
					}
					vm.patientInfo[key] = res[key];
				}
			}
			$.ajax(patientsInfoResult);
		}
	}
	
});